from rest_framework import serializers

from common.tools.money_cast import FloatToIntField
from kill.models import KillProduct


class KillProductSerializer(serializers.ModelSerializer):
    price_original = FloatToIntField(
        error_messages={
            'invalid': u'原价应为数字',
        }
    )
    price_discount = FloatToIntField(
        error_messages={
            'invalid': u'底价应为数字',
        }
    )

    class Meta:
        model = KillProduct
        fields = (
            'id',
            'shop',
            'title',
            'start_time',
            'end_time',
            'image',
            'price_original',
            'price_discount',
            'inventory',
            'shelve',
            'music',
            'desc',
            'status',
        )
        read_only_fields = (
            'id',
            'shelve'
        )
